"use client";
import { getRegisterApi } from "@/api/user";
import { useRouter } from "@/i18n";
import { Toast } from "antd-mobile";
import { useTranslations } from "next-intl";
import { FC, useState } from "react";
import dynamic from "next/dynamic";
import "../login/page.scss";

interface Props {}

const HeaderBack = dynamic(() => import('@/components/HeaderBack'));
const FromCom = dynamic(() => import('../login/component/FromCom'));
const GoogleCom = dynamic(() => import('../login/component/GoogleCom'));
const DomainFooter = dynamic(() => import('@/components/DomainFooter'));

const Register: FC<Props> = () => {
    const t = useTranslations("LoginPage");
    const router: any = useRouter();
    const [msgError, setMsgError] = useState("");
    const registerRequest = async ({ userPhone, pwd }: any) => {
        let params = { user_phone: userPhone, pwd, code: "123456" };
        let { code, msg } = await getRegisterApi(params);
        if (code == 200) {
            Toast.show({ icon: "success", content: t("registerSuc"), maskClickable: false });
            setTimeout(() => {
                router.replace("/login");
            }, 1000);
        } else {
            setMsgError(msg);
        }
    };
    return (
        <div className="register-box">
            <HeaderBack />
            <div className="content-box">
                <GoogleCom title={t("registerGoogletitle")} text={t("registerGoogletext")} />
                <FromCom type="register" callbackFun={registerRequest} msgError={msgError} />
                <DomainFooter />
            </div>
        </div>
    );
};

export default Register;
